package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import util.DBUtil;

import model.EmpStatus;
import model.JobTitle;
import dao.EmpStatusDAO;

public class EmpStatusDAOImpl implements EmpStatusDAO {
	private DBUtil dbu = new DBUtil();
	private Connection conn = null;
	private PreparedStatement pstat = null;
	private ResultSet rs = null;
	public List<EmpStatus> getAllEmpStatus() {
		List<EmpStatus> EmpStatus = new ArrayList<EmpStatus>();
		
		EmpStatus stat = new EmpStatus();
		try {
			conn = dbu.getConnection();
			pstat = conn.prepareStatement("select * from empstatus;");
			rs = pstat.executeQuery();

			while(rs.next()){
				stat.setId(rs.getInt("id"));
				stat.setName(rs.getString("name"));
				EmpStatus.add(stat);
				}

			return EmpStatus;
		} catch (Exception e) {
		} finally {
			dbu.closeConnection(conn, pstat, rs);
		}
		return EmpStatus;
	}

	public EmpStatus getEmpStatusById(int id) {
		conn= dbu.getConnection();
		EmpStatus stat = new EmpStatus();
		try {
			pstat=conn.prepareStatement("select * from empstatus where id="+id);
			rs=	pstat.executeQuery();
			while(rs.next()){
			stat.setId(rs.getInt("id"));
			stat.setName(rs.getString("name"));
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			dbu.closeConnection(conn, pstat, rs);
		}
		return stat;
	}

	public EmpStatus getEmpStatusByName(String name) {
		conn= dbu.getConnection();
		EmpStatus stat = new EmpStatus();
		try {
			pstat=conn.prepareStatement("select * from empstatus where name="+name);
			rs=	pstat.executeQuery();
			while(rs.next()){
			stat.setId(rs.getInt("id"));
			stat.setName(rs.getString("name"));
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			dbu.closeConnection(conn, pstat, rs);
		}
		return stat;
	}

}
